package com.zhanglingfei.yuekaoshop.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * @author Shichao.Lu
 * 商品类目表，类目和商品(spu)是一对多关系，类目与品牌是多对多关系
 */
@Slf4j
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@Entity
@Table(name = "tb_category")
@DynamicInsert
@DynamicUpdate
public class Category implements Serializable {

	/**
	 * 类目id
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Long id;

	@ManyToMany
	@JoinTable(name = "tb_category_brand",joinColumns = @JoinColumn(name = "category_id"),
			inverseJoinColumns = @JoinColumn(name = "brand_id"))
	private List<Brand> brandList;

	/**
	 * 类目名称
	 */
	@Column(name = "name")
	private String name;

	/**
	 * 父类目id,顶级类目填0
	 */
	@Column(name = "parent_id")
	private Long parentId;

	/**
	 * 是否为父节点，0为否，1为是
	 */
	@Column(name = "is_parent")
	private Boolean isParent;

	/**
	 * 排序指数，越小越靠前
	 */
	@Column(name = "sort")
	private Integer sort;
}
